﻿#region License
// Copyright 2008 Doug Mayer - http://code.google.com/p/nfaker
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
//     http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#endregion

namespace NFaker
{
	public class FakeAddress
	{
		internal FakeAddress() { }

		public string City()
		{
			switch (Fake.Random.Next(4))
			{
				case 0:
					return string.Format("{0} {1}{2}", CityPrefix(), Fake.Name.FirstName(), CitySuffix());
				case 1:
					return string.Format("{0} {1}", CityPrefix(), Fake.Name.FirstName());
				case 2:
					return string.Format("{0}{1}", Fake.Name.FirstName(), CitySuffix());
				default:
					return string.Format("{0}{1}", Fake.Name.LastName(), CitySuffix());
			}
		}

		public string CityPrefix()
		{
			return cityPrefixes.Random();
		}

		public string CitySuffix()
		{
			return citySuffixes.Random();
		}

		public string SecondaryAddress()
		{
			return Fake.Numerify(secondaryPrefixes.Random() + " ###");
		}

		public string StreetAddress()
		{
			return StreetAddress(false);
		}

		public string StreetAddress(bool includeSecondary)
		{
			if (includeSecondary)
				return string.Format("{0} {1} {2}", Fake.Numerify(new[] { "#####", "####", "###" }.Random()), StreetName(),
									 SecondaryAddress());

			return string.Format("{0} {1}", Fake.Numerify(new[] { "#####", "####", "###" }.Random()), StreetName());
		}

		public string StreetSuffix()
		{
			return streetSuffixes.Random();
		}

		public string StreetName()
		{
			return (Fake.Random.Next(2) == 0)
					? string.Join(" ", new[] { Fake.Name.LastName(), StreetSuffix() })
					: string.Join(" ", new[] { Fake.Name.FirstName(), StreetSuffix() });
		}

		public string UsState()
		{
			return usStates.Random();
		}

		public string UsStateAbbrev()
		{
			return usStateAbbrevs.Random();
		}

		public string UsZipCodeFive()
		{
			return Fake.Numerify("#####");
		}

		public string UsZipCodeFivePlusFour()
		{
			return Fake.Numerify("#####-####");
		}

		public string ZipCode()
		{
			return (Fake.Random.Next(2) == 0) ? UsZipCodeFive() : UsZipCodeFivePlusFour();
		}

		#region Private value arrays

		private static readonly string[] cityPrefixes = new[]
		                                                	{
		                                                		"North", "East", "West", "South", "New", "Lake", "Port"
		                                                	};

		private static readonly string[] citySuffixes = new[]
		                                                	{
		                                                		"town", "ton", "land", "ville", "berg", "burgh", "borough", "bury",
		                                                		"view", "port", "mouth", "stad", "furt", "chester", "mouth", "fort",
		                                                		"haven", "side", "shire"
		                                                	};

		private static readonly string[] secondaryPrefixes = new[]
		                                                     	{
		                                                     		"Apt.", "Suite", "Ste"
		                                                     	};

		private static readonly string[] streetSuffixes = new[]
		                                                  	{
		                                                  		"Alley", "Avenue", "Branch", "Bridge", "Brook", "Brooks", "Burg",
		                                                  		"Burgs", "Bypass", "Camp", "Canyon", "Cape", "Causeway", "Center",
		                                                  		"Centers", "Circle", "Circles", "Cliff", "Cliffs", "Club",
		                                                  		"Common", "Corner", "Corners", "Course", "Court", "Courts", "Cove"
		                                                  		, "Coves", "Creek", "Crescent", "Crest", "Crossing", "Crossroad",
		                                                  		"Curve", "Dale", "Dam", "Divide", "Drive", "Drive", "Drives",
		                                                  		"Estate", "Estates", "Expressway", "Extension", "Extensions",
		                                                  		"Fall", "Falls", "Ferry", "Field", "Fields", "Flat", "Flats",
		                                                  		"Ford", "Fords", "Forest", "Forge", "Forges", "Fork", "Forks",
		                                                  		"Fort", "Freeway", "Garden", "Gardens", "Gateway", "Glen", "Glens"
		                                                  		, "Green", "Greens", "Grove", "Groves", "Harbor", "Harbors",
		                                                  		"Haven", "Heights", "Highway", "Hill", "Hills", "Hollow", "Inlet",
		                                                  		"Inlet", "Island", "Island", "Islands", "Islands", "Isle", "Isle",
		                                                  		"Junction", "Junctions", "Key", "Keys", "Knoll", "Knolls", "Lake",
		                                                  		"Lakes", "Land", "Landing", "Lane", "Light", "Lights", "Loaf",
		                                                  		"Lock", "Locks", "Locks", "Lodge", "Lodge", "Loop", "Mall",
		                                                  		"Manor", "Manors", "Meadow", "Meadows", "Mews", "Mill", "Mills",
		                                                  		"Mission", "Mission", "Motorway", "Mount", "Mountain", "Mountain",
		                                                  		"Mountains", "Mountains", "Neck", "Orchard", "Oval", "Overpass",
		                                                  		"Park", "Parks", "Parkway", "Parkways", "Pass", "Passage", "Path",
		                                                  		"Pike", "Pine", "Pines", "Place", "Plain", "Plains", "Plains",
		                                                  		"Plaza", "Plaza", "Point", "Points", "Port", "Port", "Ports",
		                                                  		"Ports", "Prairie", "Prairie", "Radial", "Ramp", "Ranch", "Rapid",
		                                                  		"Rapids", "Rest", "Ridge", "Ridges", "River", "Road", "Road",
		                                                  		"Roads", "Roads", "Route", "Row", "Rue", "Run", "Shoal", "Shoals",
		                                                  		"Shore", "Shores", "Skyway", "Spring", "Springs", "Springs",
		                                                  		"Spur", "Spurs", "Square", "Square", "Squares", "Squares",
		                                                  		"Station", "Station", "Stravenue", "Stravenue", "Stream", "Stream"
		                                                  		, "Street", "Street", "Streets", "Summit", "Summit", "Terrace",
		                                                  		"Throughway", "Trace", "Track", "Trafficway", "Trail", "Trail",
		                                                  		"Tunnel", "Tunnel", "Turnpike", "Turnpike", "Underpass", "Union",
		                                                  		"Unions", "Valley", "Valleys", "Via", "Viaduct", "View", "Views",
		                                                  		"Village", "Village", "", "Villages", "Ville", "Vista", "Vista",
		                                                  		"Walk", "Walks", "Wall", "Way", "Ways", "Well", "Wells"
		                                                  	};

		private static readonly string[] usStates = new[]
		                                            	{
		                                            		"Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado",
		                                            		"Connecticut", "Delaware", "Florida", "Georgia", "Hawaii", "Idaho",
		                                            		"Illinois", "Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana",
		                                            		"Maine", "Maryland", "Massachusetts", "Michigan", "Minnesota",
		                                            		"Mississippi", "Missouri", "Montana", "Nebraska", "Nevada", "New",
		                                            		"Hampshire", "New", "Jersey", "New", "Mexico", "New", "York", "North",
		                                            		"Carolina", "North", "Dakota", "Ohio", "Oklahoma", "Oregon",
		                                            		"Pennsylvania", "Rhode", "Island", "South", "Carolina", "South",
		                                            		"Dakota", "Tennessee", "Texas", "Utah", "Vermont", "Virginia",
		                                            		"Washington", "West", "Virginia", "Wisconsin", "Wyoming"
		                                            	};

		private static readonly string[] usStateAbbrevs = new[]
		                                                  	{
		                                                  		"AL", "AK", "AS", "AZ", "AR", "CA", "CO", "CT", "DE", "DC", "FM",
		                                                  		"FL", "GA", "GU", "HI", "ID", "IL", "IN", "IA", "KS", "KY", "LA",
		                                                  		"ME", "MH", "MD", "MA", "MI", "MN", "MS", "MO", "MT", "NE", "NV",
		                                                  		"NH", "NJ", "NM", "NY", "NC", "ND", "MP", "OH", "OK", "OR", "PW",
		                                                  		"PA", "PR", "RI", "SC", "SD", "TN", "TX", "UT", "VT", "VI", "VA",
		                                                  		"WA", "WV", "WI", "WY", "AE", "AA", "AP"
		                                                  	};

		#endregion
	}
}